package org.xu.controller;

import com.alibaba.fastjson.JSONObject;
import com.core.base.Reply;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xu.dto.MenuDTO;
import org.xu.dto.UserInfoDTO;
import org.xu.request.LoginRequest;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequestMapping("/user/")
@Controller
public class LoginController {

    @ResponseBody
    @RequestMapping("getLogin")
    public Reply<String> getLogin( LoginRequest loginRequest){
        log.info("登录用户-{}", loginRequest);
        return Reply.success("login success");
    }
    @ResponseBody
    @RequestMapping("/leave/count")
    public Reply<Integer> leaveCount(){
        return Reply.success(3);
    }

    @ResponseBody
    @RequestMapping("login")
    public Reply<UserInfoDTO> login(@RequestBody LoginRequest loginRequest){
        log.info("登录用户-{}", JSONObject.toJSONString(loginRequest));
        UserInfoDTO dto = new UserInfoDTO();
        dto.setAccount(loginRequest.getUserName());
        dto.setUserName("张三");
        dto.setLogoPicUrl("http://...");
        /*int temp = new Random(10).nextInt();
        if (temp % 2 == 0){
            return Reply.failure("密码错误" + temp);
        }*/
        return Reply.success(dto);
    }

    @ResponseBody
    @RequestMapping("/menu/list")
    public Reply<List<MenuDTO>> menuList(@RequestBody LoginRequest loginRequest){
        List<MenuDTO> list = new ArrayList<>();

        return Reply.success(list);
    }


}
